package com.lizhangjun.controller;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.lizhangjun.domain.QItem;
import com.lizhangjun.entity.Result;
import com.lizhangjun.service.QItemService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author lizhangjun
 * @since 2021-06-23
 */
@Api(tags = {"视频相关接口"} )
@RestController
@RequiredArgsConstructor
@RequestMapping("/q-item")
public class QItemController {

    private final QItemService itemService;

    /**
     * 添加视频
     * @param item 视频数据
     * @return 是否添加成功
     */
    @ApiOperation("添加视频")
    @PostMapping("/add")
    public Result add(@RequestBody QItem item){
        if(itemService.saveOrUpdate(item)){
            return Result.success();
        }else{
            return Result.fail("添加视频失败");
        }
    }

    /**
     * 视频分页数据
     * @param pageNo 第几页
     * @return 视频列表
     */
    @ApiOperation("分页查找视频数据")
    @GetMapping("/list/{pageNo}")
    public Result list(@PathVariable Integer pageNo){
        LambdaQueryWrapper<QItem> wrapper = new LambdaQueryWrapper<>();
        IPage<QItem> page = new Page<>(pageNo, 8);
        IPage<QItem> iPage = itemService.page(page, wrapper);
        return Result.success(iPage.getRecords());

    }

    /**
     * 获取所有视频
     * @return 视频数据
     */
    @ApiOperation("获取所有视频")
    @GetMapping("/all")
    public Result all(){
        return Result.success(itemService.list());

    }
}

